package cn.cyber.wxfire.config;

import org.springframework.web.servlet.LocaleResolver;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

//解析器
public class MyLocaleResolve implements LocaleResolver {

    //解析请求
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        //获取请求中的语言参数
        String language=request.getParameter("l");
        //没有就为默认的
        Locale L=Locale.getDefault();
        //不为空
        if(!StringUtils.isEmpty(language))
        {
            String[] s=language.split("_");
            L=new Locale(s[0],s[1]);
        }

        return L;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}
